<template>
	<button type="button" hover-class="hover" :class="[...className]">
		<slot>button</slot>
	</button>
</template>

<script lang="uts" setup name="m-button">
	const props = defineProps({
		type: {
			type: String,
			default: 'default',
		},
		plain: {
			type: Boolean,
			default: false
		}
	});

	type ClassJson = {
		default : Array<String>
		primary : Array<String>
		success : Array<String>
		warning : Array<String>
		error : Array<String>
	}

	const classJson : ClassJson = {
		'default': ['m-button'],
		'primary': ['m-button', 'primary-button'],
		'success': ['m-button', 'success-button'],
		'warning': ['m-button', 'warning-button'],
		'error': ['m-button', 'error-button'],
	}
	const className = ref([] as string[])

	onMounted(() => {
		className.value = classJson[props.type] as string[]
	})
</script>

<style lang="scss" scoped>
	.m-button {
		color: #333333;
		background-color: #ffffff;
		border-radius: 10rpx;
	}

	.primary-button {
		color: #ffffff;
		background-color: $uni-color-primary;
	}

	.success-button {
		color: #ffffff;
		background-color: $uni-color-success;
	}

	.warning-button {
		color: #ffffff;
		background-color: $uni-color-warning;
	}

	.error-button {
		color: #ffffff;
		background-color: $uni-color-error;
	}

	.hover {
		opacity: 0.8;
	}
</style>